package leetcode; /**
 * description:
 * author:张腾
 * date:2021-06-17
 */

/**
 * 翻转一棵二叉树
 */
public class leetcode226 {
    public TreeNode invertTree(TreeNode root) {

        if (root==null) return null;

        //方法一
        TreeNode left = invertTree(root.left);
        TreeNode right = invertTree(root.right);
        root.left = right;
        root.right = left;

        //方法二
        TreeNode tmp = root.left;
        root.left = root.right;
        root.right = tmp;
        invertTree(root.left);
        invertTree(root.right);

        return root;
    }
}
